package com.ruyuan.event.streaming.schema;

import com.ruyuan.event.streaming.pojo.EventClientLog;
import org.apache.flink.api.common.serialization.DeserializationSchema;
import org.apache.flink.api.common.serialization.SerializationSchema;
import org.apache.flink.api.common.typeinfo.TypeHint;
import org.apache.flink.api.common.typeinfo.TypeInformation;

import java.io.IOException;

public class EventClientLogSchema implements DeserializationSchema<EventClientLog>, SerializationSchema<EventClientLog> {

    @Override
    public EventClientLog deserialize(byte[] message) throws IOException {
        return EventClientLog.parseFrom(message);
    }

    @Override
    public boolean isEndOfStream(EventClientLog nextElement) {
        return false;
    }

    @Override
    public byte[] serialize(EventClientLog eventClientLog) {
        return eventClientLog.toByteArray();
    }

    @Override
    public TypeInformation<EventClientLog> getProducedType() {
        return TypeInformation.of(new TypeHint<EventClientLog>() {});
    }
}
